<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">角色名</label>
                    <div class="layui-input-block">
                        <input type="text" name="roleName"  autocomplete="off" placeholder="请输入角色名" class="layui-input" lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">角色标识</label>
                    <div class="layui-input-block">
                        <input type="text"  name="roleCode" lay-verify="required" autocomplete="off" placeholder="请输入角色标识" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">角色描述</label>
                    <div class="layui-input-block">
                        <input type="text"  name="details" lay-verify="required" autocomplete="off" placeholder="请输入角色描述" class="layui-input">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="role-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="/component/layui/layui.js"></script>
<script src="/component/pear/pear.js"></script>
<script>
layui.use(['form','jquery','select'],function(){
    let form = layui.form;
    let $ = layui.jquery;
    let select = layui.select;
    form.on('submit(role-save)', function(data){
        $.ajax({
            url:'/role/create',
            data:JSON.stringify(data.field),
            dataType:'json',
            contentType:'application/json',
            type:'post',
            success:function(){
                layer.msg('角色新增成功',{icon:1,time:1000},function(){
                    parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                    parent.layui.table.reload("role-table");
                });
            },
            error: function (data) {
                layer.msg(data.responseJSON.detail,{icon:2,time:1000});
            }
        })
        return false;
    });
})
</script>
</body>
</html>
